export function $animationInterVal(callback, delay, immediate) {
  let isLunch = false;
  if (immediate) {
    if (!isLunch) {
      callback && callback();
      isLunch = true;
    }
  }
  const requestAnimationFrame =
    window.requestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.msRequestAnimationFrame;
  let timer;
  let $start = Date.now();
  let flag = true;
  function fn() {
    const loop = () => {
      if (flag) {
        const now = Date.now();
        if (now - $start > delay) {
          callback && callback();
          $start = now;
        }
        timer = requestAnimationFrame(loop);
      }
    };
    timer = requestAnimationFrame(loop);
  }
  fn();
  return () => {
    flag = false;
    cancelAnimationFrame(timer);
  };
}